package org.nbict.iot.protocol.type;

import java.util.ArrayList;
import java.util.List;

/**
 * 报文域定义
 * Created by songseven on 18/6/9.
 */
public class ProtocolField {
    private Integer id;
    private String name; //报文域名称
    private FieldType type; //报文域类型
    private Integer fixedPacketLen; //固定值报文域长度
    private String packetLenExpression; //可变值报文域长度计算表达式
    private Integer flowingPointer;//动态域起始位置
    private Integer flowingTagLen; //识别动态域类型的tag长度
    private Integer tag; //动态域的类型标识
    private String tagExpression; //动态域的类型计算表达式
    private String flowingFieldNum; //包含的域总数,只有ARRAY类型符合
    private Boolean cached; //是否需要加载到上下文中
    private String description; //描述
    private Integer index;
    private Integer aliasTypeTag; //域的别名id
    private String unit;

    private FieldValueCast convertor; //域值类型转换

    private List properties; //报文域的属性

    public ProtocolField() {
    }

    /**
     * 测试
     * @param id
     * @param name
     * @param type
     */
    public ProtocolField(Integer id, String name, FieldType type) {
        this.id = id;
        this.name = name;
        this.type = type;
    }

    /**
     *
     * @param id
     * @param name
     * @param type
     * @param fixedPacketLen
     * @param flowingTagLen
     * @param tag
     * @param flowingFieldNum
     * @param isContext
     * @param index
     */
    public ProtocolField(
            Integer id,
            String name,
            FieldType type,
            Integer fixedPacketLen,
            Integer flowingTagLen,
            Integer tag,
            String flowingFieldNum,
            Boolean isContext,
            Integer index) {

        this.id = id;
        this.name = name;
        this.type = type;
        this.fixedPacketLen = fixedPacketLen;
        this.flowingTagLen = flowingTagLen;
        this.tag = tag;
        this.flowingFieldNum = flowingFieldNum;
        this.cached = isContext;
        this.index = index;
    }



    public Integer getId() {
        return id;
    }

    public ProtocolField setId(Integer id) {
        this.id = id;
        return this;
    }

    public String getName() {
        return name;
    }

    public ProtocolField setName(String name) {
        this.name = name;
        return this;
    }

    public FieldType type() {
        return getType();
    }

    public FieldType getType() {
        return type;
    }

    public ProtocolField setType(FieldType type) {
        this.type = type;
        return this;
    }

    public Integer getFixedPacketLen() {
        return fixedPacketLen;
    }

    public ProtocolField setFixedPacketLen(Integer fixedPacketLen) {
        this.fixedPacketLen = fixedPacketLen;
        return this;
    }

    public Integer getFlowingPointer() {
        return flowingPointer;
    }

    public ProtocolField setFlowingPointer(Integer flowingPointer) {
        this.flowingPointer = flowingPointer;
        return this;
    }

    public Integer getFlowingTagLen() {
        return flowingTagLen;
    }

    public ProtocolField setFlowingTagLen(Integer flowingTagLen) {
        this.flowingTagLen = flowingTagLen;
        return this;
    }

    public Integer getTag() {
        return tag;
    }

    public ProtocolField setTag(Integer tag) {
        this.tag = tag;
        return this;
    }

    public String getTagExpression() {
        return tagExpression;
    }

    public ProtocolField setTagExpression(String tagExpression) {
        this.tagExpression = tagExpression;
        return this;
    }

    public String getFlowingFieldNum() {
        return flowingFieldNum;
    }

    public ProtocolField setFlowingFieldNum(String flowingFieldNum) {
        this.flowingFieldNum = flowingFieldNum;
        return this;
    }

    public Boolean getCached() {
        return cached;
    }

    public ProtocolField setCached(Boolean cached) {
        this.cached = cached;
        return this;
    }

    public String getDescription() {
        return description;
    }

    public ProtocolField setDescription(String description) {
        this.description = description;
        return this;
    }

    public Integer getIndex() {
        return index;
    }

    public ProtocolField setIndex(Integer index) {
        this.index = index;
        return this;
    }

    public FieldValueCast getConvertor() {
        return convertor;
    }

    public ProtocolField setConvertor(FieldValueCast convertor) {
        this.convertor = convertor;
        return this;
    }

    public String getPacketLenExpression() {
        return packetLenExpression;
    }

    public ProtocolField setPacketLenExpression(String packetLenExpression) {
        this.packetLenExpression = packetLenExpression;
        return this;
    }

    public Integer getAliasTypeTag() {
        return aliasTypeTag;
    }

    public ProtocolField setAliasTypeTag(Integer aliasTypeTag) {
        this.aliasTypeTag = aliasTypeTag;
        return this;
    }

    public String getUnit() {
        return unit;
    }

    public ProtocolField setUnit(String unit) {
        this.unit = unit;
        return this;
    }

    public List<ProtocolField> getProperties() {
        return properties;
    }

    public ProtocolField setProperties(List<ProtocolField> properties) {
        this.properties = properties;
        return this;
    }

    public ProtocolField addProperties(ProtocolField property) {

        if (this.properties == null) {
            this.properties = new ArrayList<ProtocolField>();
        }
        this.properties.add(property);
        return this;
    }

    @Override
    public String toString() {
        return this.description;
    }

}
